//
//  DaTiYongShiView.m
//  SchoolHelper
//
//  Created by 任辰东 on 2022/8/26.
//  Copyright © 2022 JSY. All rights reserved.
//

#import "DaTiYongShiView.h"
#import "ReportCardTitleView.h"

@interface DaTiYongShiView ()
@property (nonatomic, strong) ReportCardTitleView *titleView;
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UILabel *totalLabel;
@property (nonatomic, strong) UILabel *zhengqueLabel;
@property (nonatomic, strong) UILabel *cuowuLabel;

@property (nonatomic, strong) UILabel *totalMarkLabel;
@property (nonatomic, strong) UILabel *zhengqueMarkLabel;
@property (nonatomic, strong) UILabel *cuowuMarkLabel;
@end

@implementation DaTiYongShiView

-(void)configViewWithModel:(ReportCardTiDetailModel *)model
{
    self.totalLabel.text = [self time:model.guiding_time];
    self.zhengqueLabel.text = [self time:model.dati_time];
    self.cuowuLabel.text = [self time:model.chaju_time];
}

-(NSString *)time:(NSString *)timeStr
{
    NSString *targetTime = [timeStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
    
    NSInteger time = targetTime.integerValue;

    NSInteger m = time/60;
    NSInteger s = time%60;

    NSString *minute = @"";
    if (m > 9) {
        minute = [NSString stringWithFormat:@"%ld",m];
    }else{
        minute = [NSString stringWithFormat:@"0%ld",m];
    }
    
    NSString *second = @"";
    if (s > 9) {
        second = [NSString stringWithFormat:@"%ld",s];
    }else{
        second = [NSString stringWithFormat:@"0%ld",s];
    }
    
    NSString *mark;
    if ([timeStr containsString:@"-"]) {
        mark = @"-";
    }else{
        mark = @"";
    }
    
    NSString *sTandardtime = [NSString stringWithFormat:@"%@%@:%@",mark,minute,second];
    
    return sTandardtime;
}

-(void)setupViews
{
    self.backgroundColor = UIColorFromHex(kColorWhite);
    [self addSubview:self.titleView];
    [self addSubview:self.containerView];
    [self.containerView addSubview:self.totalLabel];
    [self.containerView addSubview:self.totalMarkLabel];
    [self.containerView addSubview:self.zhengqueLabel];
    [self.containerView addSubview:self.zhengqueMarkLabel];
    [self.containerView addSubview:self.cuowuLabel];
    [self.containerView addSubview:self.cuowuMarkLabel];
}

-(void)setupLayout
{
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.right.equalTo(self);
    }];
    [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.titleView.mas_bottom).offset(10);
        make.left.equalTo(self).offset(15);
        make.bottom.right.equalTo(self).offset(-15);
    }];
    
    CGFloat width = (kScreenWidth - 15 *2)/3;
    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.containerView).offset(15);
        make.left.equalTo(self.containerView).offset(15);
        make.width.mas_equalTo(width);
    }];
    
    [self.totalMarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.totalLabel.mas_bottom).offset(5);
        make.left.equalTo(self.containerView).offset(15);
        make.width.mas_equalTo(width);
        make.bottom.equalTo(self.containerView).offset(-15);
    }];
    
    [self.zhengqueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.containerView).offset(15);
        make.left.equalTo(self.totalLabel.mas_right).offset(0);
        make.width.mas_equalTo(width);
    }];
    
    [self.zhengqueMarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.zhengqueLabel.mas_bottom).offset(5);
        make.left.equalTo(self.totalMarkLabel.mas_right).offset(0);
        make.width.mas_equalTo(width);
        make.bottom.equalTo(self.containerView).offset(-15);
    }];
    
    [self.cuowuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.containerView).offset(15);
        make.left.equalTo(self.zhengqueLabel.mas_right).offset(0);
        make.width.mas_equalTo(width);
    }];
    
    [self.cuowuMarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.cuowuLabel.mas_bottom).offset(5);
        make.left.equalTo(self.zhengqueMarkLabel.mas_right).offset(0);
        make.width.mas_equalTo(width);
        make.bottom.equalTo(self.containerView).offset(-15);
    }];
}

-(ReportCardTitleView *)titleView
{
    if (!_titleView) {
        _titleView = [ReportCardTitleView new];
        [_titleView configViewWithTitle:@"答题用时"];
    }
    return _titleView;
}

-(UIView *)containerView
{
    if (!_containerView) {
        _containerView = [UIView new];
        _containerView.backgroundColor = UIColorFromHex(kColorWhite);
        _containerView.layer.cornerRadius = 5;
        _containerView.layer.masksToBounds = YES;
        _containerView.layer.borderWidth = kOnePixel;
        _containerView.layer.borderColor = UIColorFromHex(kColorLine).CGColor;
    }
    return _containerView;
}

-(UILabel *)totalLabel
{
    if (!_totalLabel) {
        _totalLabel = [UILabel new];
        _totalLabel.textColor = UIColorFromHex(0x000000);
        _totalLabel.font = UIFontSize(15);
        _totalLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _totalLabel;
}

-(UILabel *)zhengqueLabel
{
    if (!_zhengqueLabel) {
        _zhengqueLabel = [UILabel new];
        _zhengqueLabel.textColor = UIColorFromHex(0x000000);
        _zhengqueLabel.font = UIFontSize(15);
        _zhengqueLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _zhengqueLabel;
}

-(UILabel *)cuowuLabel
{
    if (!_cuowuLabel) {
        _cuowuLabel = [UILabel new];
        _cuowuLabel.textColor = UIColorFromHex(0x000000);
        _cuowuLabel.font = UIFontSize(15);
        _cuowuLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _cuowuLabel;
}

-(UILabel *)totalMarkLabel
{
    if (!_totalMarkLabel) {
        _totalMarkLabel = [UILabel new];
        _totalMarkLabel.text = @"规定用时";
        _totalMarkLabel.textColor = UIColorFromHex(0x666666);
        _totalMarkLabel.font = UIFontSize(11);
        _totalMarkLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _totalMarkLabel;
}

-(UILabel *)zhengqueMarkLabel
{
    if (!_zhengqueMarkLabel) {
        _zhengqueMarkLabel = [UILabel new];
        _zhengqueMarkLabel.text = @"你的用时";
        _zhengqueMarkLabel.textColor = UIColorFromHex(0x666666);
        _zhengqueMarkLabel.font = UIFontSize(11);
        _zhengqueMarkLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _zhengqueMarkLabel;
}

-(UILabel *)cuowuMarkLabel
{
    if (!_cuowuMarkLabel) {
        _cuowuMarkLabel = [UILabel new];
        _cuowuMarkLabel.text = @"差距用时";
        _cuowuMarkLabel.textColor = UIColorFromHex(0x666666);
        _cuowuMarkLabel.font = UIFontSize(11);
        _cuowuMarkLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _cuowuMarkLabel;
}
@end
